export function now(split?: string) {
  split = split || "-";
  const date = new Date();

  return `${date.getFullYear()}${split}${(date.getMonth() + 1)
    .toString()
    .padStart(2, "0")}${split}${date.getDate().toString().padStart(2, "0")}`;
}

// 返回当前的时分秒信息
export function nowTime(split?: string) {
  split = split || ":";
  const date = new Date();

  return `${date.getHours()}${split}${date
    .getMinutes()
    .toString()
    .padStart(2, "0")}${split}${date.getSeconds().toString().padStart(2, "0")}`;
}

// 返回当前的中文星期
export function nowWeek(): string {
  const now = new Date();
  const day = now.getDay();
  const weeks = [
    "星期日",
    "星期一",
    "星期二",
    "星期三",
    "星期四",
    "星期五",
    "星期六",
  ];
  return weeks[day];
}

export function lastMonth(i: number) {
  i = i || 1;
  const date = new Date();
  date.setMonth(date.getMonth() - i);

  return `${date.getFullYear()}-${(date.getMonth() + 1)
    .toString()
    .padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`;
}

// 获取当前的unix时间戳
export function nowTimeStamp() {
  return Number(new Date().getTime().toString().slice(0, -3));
}

// 根据 "HH:MM:SS" 形式的字符串计算出总共的秒数
export function getSecondsFromString(time: string) {
  const timeArr = time.split(":");
  return (
    Number(timeArr[0]) * 3600 + Number(timeArr[1]) * 60 + Number(timeArr[2])
  );
}
